package cn.tedu.wms.passport.controller;

import cn.tedu.wms.passport.pojo.dto.InputOutputAddNewDTO;
import cn.tedu.wms.passport.pojo.dto.InputOutputUpdateDTO;
import cn.tedu.wms.passport.pojo.vo.InputOutputListItemVO;
import cn.tedu.wms.passport.pojo.vo.InputOutputStandardVO;
import cn.tedu.wms.passport.service.impl.InputOutputServiceImpl;
import cn.tedu.wms.passport.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 *
 *
 * @author 刘哲兮
 * @version 0.0.1
 */
@Slf4j
@Api(tags = "08. 出入库管理模块")
@Validated
@RestController
@RequestMapping("/inputoutput")
public class InputOutputController {

    @Autowired
    InputOutputServiceImpl inputOutputService;

    public InputOutputController() {
        log.debug("创建控制器对象：InputOutputController");
    }
    @ApiOperation("添加出入库")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated InputOutputAddNewDTO inputOutputAddNewDTO) {
        log.debug("开始处理【添加出入库】的请求，参数：{}", inputOutputAddNewDTO);
        inputOutputService.addNew(inputOutputAddNewDTO);
        return JsonResult.ok();
    }


    @ApiOperation("删除出入库信息")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "出入库id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除出入库】的请求，参数：{}", id);
        inputOutputService.delete(id);
        return JsonResult.ok();
    }


    @ApiOperation("修改出入库详情")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "出入库id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> updateById(@PathVariable Long id, InputOutputUpdateDTO inputOutputUpdateDTO) {
        log.debug("开始处理【修改出入库详情】的请求：id={}, brandUpdateDTO={}", id, inputOutputUpdateDTO);
        inputOutputService.updateInfoById(id, inputOutputUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id查询出入库详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "出入库id", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<InputOutputStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询出入库详情】的请求：id={}", id);
        InputOutputStandardVO album = inputOutputService.getStandardById(id);
        return JsonResult.ok(album);
    }


    @ApiOperation("查询出入库列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult<List<InputOutputListItemVO>> list() {
        log.debug("开始处理【查询出入库列表】的请求");
        List<InputOutputListItemVO> list = inputOutputService.list();
        return JsonResult.ok(list);
    }

    @Deprecated
    @ApiOperation("删除出入库测试")
    @ApiOperationSupport(order = 900)
    @PostMapping("/{id:[a-z]+}/delete/test")
    public String delete(@PathVariable String id) {
        log.debug("【测试】开始处理【删除出入库】的请求，参数（纯字母）：{}", id);
        return "OK";
    }


}
